export default {
	methods: {
		toHome() {
			uni.reLaunch({
				url: '/pages/index/home/home'
			})
		},
		goLogin(url, opts) {
			if (uni.getStorageSync('Token') && this.$store.state.userInfo && this.$store.state.userInfo.username) {
				this.goRoute(url, opts)
			} else {
				this.goRoute('/pages/index/login/login')
			}
		},
		isLogin() {
			if (uni.getStorageSync('Token')) return true;
			return false;
		},
		goBack() {
			var pages = getCurrentPages();
			if (pages.length > 1) {
				uni.navigateBack({
					delta: 1
				});
			} else {
				uni.reLaunch({
					url: '/pages/index/home/home'
				})
			}
		},
		previewImg(url) {
			uni.previewImage({
				urls: [url]
			})
		},
		showToast(text, type) {
			uni.showToast({
				title: text,
				icon: type || 'none'
			})
		},
		goRoute(url, obj) {
			this.$u.route(url, obj)
		},
		openPdf(url, fileName) {
			uni.showLoading({
				title: '加载中...'
			})
			if (!fileName) {
				uni.downloadFile({
					url: url,
					success: function(res) {
						uni.hideLoading()
						uni.openDocument({
							filePath: res.tempFilePath,
							showMenu: true,
							success: function(res) {}
						});
					},
					fail(err) {
						console.log(err)
					}
				});
			} else {
				console.log(uni.env, 'uni.env');
				uni.downloadFile({
					url: url,
					filePath: `${uni.env.USER_DATA_PATH}/${fileName}`,
					success: function(res) {
						uni.hideLoading()
						uni.openDocument({
							filePath: res.filePath,
							showMenu: true,
							success: function(res) {
							},
							fail(err) {
								console.log(err, 'err');
							}
						});
					},
					fail(err) {
						console.log(err)
					}
				});
			}
			
		},
		copyText(text) {
			uni.setClipboardData({
				data: text,
				success(res) {
					uni.showToast({
						title: '复制成功',
						icon: 'none'
					})
				},
				fail(err) {}
			})
		},
		// 拨打电话
		makeCall(number) {
			console.log(number)
			uni.makePhoneCall({
				phoneNumber: number,
				success: () => {
					console.log('拨打电话成功！');
				},
				fail: (err) => {
					console.error('拨打电话失败！', err);
				}
			});
		},

	}
}